package com.sc.byahi.user.server;

import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Mailer {
	private static Logger logger = Logger.getLogger("com.sc.byahi.user.server.Mailer");

	public static Boolean sendMail(String body, String... to) {
		Properties props = new Properties();
		Session session = Session.getDefaultInstance(props, null);
		try {
			Message msg = new MimeMessage(session);
			msg.setFrom(new InternetAddress("admin@byahi.com"));
			InternetAddress[] address = new InternetAddress[to.length];
			for (int i = 0; i < to.length; i++) {
				address[i] = new InternetAddress(to[i]);
			}
			msg.addRecipients(Message.RecipientType.TO, address);
			msg.setSubject("Email from Byahi Administrator.");
			msg.setText(body);
			Transport.send(msg);
			return Boolean.TRUE;
		} catch (Exception e) {
			logger.log(Level.SEVERE, "Error while sending email.", e);
		}
		return Boolean.FALSE;
	}

	public static void sendWelcomeMail(String... to) {
		// String sub =

	}

}
